package com.ysd.twocrm.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ysd.twocrm.entity.Permission;
import com.ysd.twocrm.entity.RolesPermission;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface PermissionMapper extends BaseMapper<Permission> {
    //获取当前角色id下的全部权限id
    @Select(value = "select * from rolespermission where roleid=#{roleId}")
    List<RolesPermission> findpermissionIdByRoleId(Integer roleId);
    //根据角色id来删除角色权限表
    @Delete(value = "delete from rolespermission where roleid=#{roleId}")
    Integer delPermissionRolesByRolesId(Integer roleId);
    //添加角色权限表
    @Insert(value = "insert into rolespermission value(0,#{roleId},#{permissionId})")
    Integer insertPermissionRoles(Integer roleId,String permissionId);
    //查询当前用户所拥有的角色所拥有的权限
    @Select(value = "select * from permission where permissionId in(select permissionId from rolespermission where roleid in(select roleid from userroles where userId =(select userid from users where userid=#{userId})))")
    List<Permission> PERMISSION_LIST(Integer userId);
    //根据权限名称修改权限名称
    @Update(value = "update permission set permissionModule=#{permissionModulevalue} where permissionModule= #{permissionModule}")
    Integer exitPermissionByName(String permissionModulevalue,String permissionModule);
}
